﻿#region Using Directives

using System;
using System.Net;
using System.Text;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Web;

using QuickDev.Common;
using QuickDev.Common.Utils;
using QuickDev.Common.Audit;
using QuickDev.Localization;
using QuickDev.Web.UI.Controls;

using QuickDev.Model;
using QuickDev.Caching;
using QuickDev.BLL;
using QuickDev.Services;

#endregion

namespace QuickDev.Web.App.controls
{
    public partial class ucReturnOrderHeader : AdminControl
    {
        #region Constants


        #endregion

        #region Member Variables

        private int orderId = 0;

        #endregion

        #region Page Events

        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load( object sender , EventArgs e )
        {
            try
            {
                orderId = Utility.GetIntParameter( "orderId" );

                SetProperties();

                if ( !IsPostBack )
                {
                    LoadReturnOrderHeader( ReturnOrderHeaderCache.GetModel( orderId ) );
                }
            }
            catch ( Exception ex )
            {
                Logger.Error( typeof( ucReturnOrderHeader ).Name + ".Page_Load" , ex );
                base.MasterPage.MessageCenter.DisplayCriticalMessage( ex.Message );
            }
        }

        #endregion

        #region Methods

        #region Protected

        /// <summary>
        /// protected string FecthUpdateByText( string updateBy )
        /// </summary>
        /// <param name="updateBy">updateBy</param>
        /// <returns></returns>
        protected string FecthUpdateByText( string updateBy )
        {
            return WebUtility.FecthUpdateByText( updateBy );
        }

        #endregion

        #region Private

        /// <summary>
        /// Sets the CustomerEdit properties.
        /// </summary>
        private void SetProperties()
        {
        }

        /// <summary>
        /// LoadCustomer( Customer model )
        /// </summary>
        /// <param name="model">model</param>
        private void LoadReturnOrderHeader( ReturnOrderHeader model )
        {
            lblCreatedDateDisplay.Text = ServiceUtility.GetFormattedDate( model.CreatedOn );
            lblCustomerStatusDisplay.Text = ServiceUtility.GetFormattedStatus( model.ReturnOrderStatusId , ReturnOrderStatusCache.GetModel( model.ReturnOrderStatusId ).Name );
            lblCreatedByDisplay.Text = FecthUpdateByText( model.CreatedBy.ToString() );
            lblUpdatedByDisplay.Text = FecthUpdateByText( model.UpdatedBy.ToString() );

            lblWangWangIdDisplay.Text = model.WangWangId;
            lblCustomerNameDisplay.Text = model.CustomerName;
            lblCustomerCellPhoneNumberDisplay.Text = model.CustomerCellphone;
            lblCustomerAddressDisplay.Text = model.CustomerAddress;
        }

        #endregion

        #endregion
    }
}